import 'package:flutter/material.dart';

// 实体类定义
class LoadTaskData {
  final int id;
  final String loadNumber;
  final String warehouse;
  final String equipment;
  final List<LoadLine> loadLines;
  final String lpnNumber;
  final String itemNumber;
  final String packKey;
  final int quantity;

  LoadTaskData({
    required this.id,
    required this.loadNumber,
    required this.warehouse,
    required this.equipment,
    required this.loadLines,
    required this.lpnNumber,
    required this.itemNumber,
    required this.packKey,
    required this.quantity,
  });

  factory LoadTaskData.fromJson(Map<dynamic, dynamic> json) {
    return LoadTaskData(
      id: json['id'] ?? 0,
      loadNumber: json['load_number'] ?? '',
      warehouse: json['warehouse']?.toString() ?? '',
      equipment: json['equipment'] ?? '',
      loadLines: (json['load_lines'] as List<dynamic>?)
              ?.map((line) => LoadLine.fromJson(line))
              .toList() ??
          [],
      lpnNumber: json['lpn_number'] ?? '',
      itemNumber: json['item_number'] ?? '',
      packKey: json['pack_key'] ?? '',
      quantity: json['quantity'] ?? 0,
    );
  }
}

class LoadLine {
  final int id;
  final String? lpnNumber;
  final String itemNumber;
  final int quantity;
  final String itemName;
  final String itemDesc;
  final String packKey;
  final String status;

  LoadLine({
    required this.id,
    required this.lpnNumber,
    required this.itemNumber,
    required this.quantity,
    required this.itemName,
    required this.itemDesc,
    required this.packKey,
    required this.status,
  });

  factory LoadLine.fromJson(Map<String, dynamic> json) {
    return LoadLine(
      id: json['id'] ?? 0,
      lpnNumber: json['lpn_number']??'N/A',
      itemNumber: json['item_number'] ?? 'N/A',
      quantity: json['quantity'] ?? 0,
      itemName: json['item_name'] ?? 'N/A',
      itemDesc: json['item_desc'] ?? 'N/A',
      packKey: json['pack_key'] ?? 'N/A',
      status: json['status'] ?? 'N/A',
    );
  }
}
